/*******************************************\
|					    |
| This displays the Medium Level high scores|
|					    |
| Status: Unfinished. Cannot write new high |
| score to file.			    |
| 					    |
\*******************************************/

#include <ncurses.h>
#include <stdio.h>
#include <string.h>

FILE *fp;

int medium_score(char name[], int score, int set_score)
{
	int x, y;
	char i, buffer[20];
	
	clear();

	mvprintw(2, (getmaxx(stdscr)/2) - 5, "HIGH SCORES");
	mvprintw(3, (getmaxx(stdscr)/2) - 5, "LEVEL: MEDIUM");
	refresh();

	fp = fopen("/home/students/j.pitel/the_Commuter/highscore_list_m.txt", "a");

	if(set_score == 1)
		fprintf(fp, "%s\t\t%6d", name, score);

	fclose(fp);
	
	system("./enter_medium.sh");

	x = 1;
	y = 5;

	fp = fopen("/home/students/j.pitel/the_Commuter/highscore_list_m.txt", "r");

	while(fgets(buffer, 15, fp) != NULL)
	{
		y++;
		mvprintw(y, x, "%s", buffer);
	}	

	fclose(fp);

	mvprintw(23, 1, "Press q to continue.");
	refresh();

	while((i = getch()) != 'q') {}	

	return;	
}

int main()
{
	int x, y, set_score = 1, score;
	char i;
	char buffer[20], name[3];

	initscr();
	cbreak();
	keypad(stdscr, TRUE);
	curs_set(0);

	clear();

	mvprintw(5, 7, "Please enter your initials (xxx): ");
	refresh();
	getstr(name);
	mvprintw(7, 7, "Please enter your score (xxxxxx): ");
	refresh();
	scanw("%6d", &score);
	
	medium_score(name, score, set_score);
	
	endwin();

	return;
}
